package com.time.company.common.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.text.TextUtils;

import com.time.company.R;
import com.time.company.utils.NetWorkUtils;
import com.time.company.utils.ToastUtils;


/**
 * 动态监听网络变化接收器
 * Created by Bing on 2016/8/23.
 * E-mail is tx16bing@163.com
 */
public class NetReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
        if (context == null) {
            return;
        }

        String action = intent.getAction();
        if (TextUtils.equals(action, ConnectivityManager.CONNECTIVITY_ACTION)) {
            //网络变化的时候会发送通知
            if (!NetWorkUtils.isNetAvailable(context)) {
//                noNet();
                ToastUtils.showLong(context.getString(R.string.network_error));
            }else {
//                hasNet();
            }
            return;
        }
    }

//    public abstract void noNet();
//    public abstract void hasNet();
}
